package explorandum.f09.g5;

import explorandum.GameConstants;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

public class Feature {
	
	public  ArrayList<Cell> cells; 
	private final int terrain;
	public  Boolean   claimed;
	public  int       visibleFootsteps;
	
	private ArrayList<Cell> border;

	Feature(int terrain) {
		this.terrain = terrain;
		cells = new ArrayList<Cell>();
		border = new ArrayList<Cell>();
		claimed = false;
		visibleFootsteps = 0;
	}
	
	public void addAll(Feature source){
		for(int i=0; i<source.cells.size(); i++){
			Cell c = source.cells.get(i);
			if(c.terrain == terrain && !cells.contains(c)) {
				cells.add(c);
			}
		}
	}
	
	boolean hasCell(Cell cell){
		return cells.contains(cell);
	}
	
	void addCell(Cell cell){
		if(!cells.contains(cell)) {
			cells.add(cell);
		}
	}
	
	public ArrayList<Cell> getCoastline(Map map) {		
		for (Cell c : cells) {
			ArrayList<Cell> neighbors = map.getImmediateNeighbors(c.location);
			for (Cell neighbor : neighbors) {
				if(neighbor != null && neighbor.terrain == GameConstants.LAND && !(border.contains(neighbor))) {
					border.add(neighbor);
				}
			}
		}
		
		return border;
	}


	public int getTerrain() {
		return terrain;
	}
	
	public int getSize(){
		return cells.size();
	}
}
